package com.itheima.day09_set;

import java.util.Comparator;
import java.util.TreeSet;

public class Test02 {
    /*
    【编号：1505】现有若干图书信息（包含名称title、作者author、定价price）需要存储到set集合中，
    保证集合中无重复元素，并遍历查看。
    可以认为所有信息都相同的图书为重复数据。
     */
    public static void main(String[] args) {
        TreeSet<Book> t = new TreeSet<>((o1, o2) -> {
            int result = o1.getPrice() - o2.getPrice();
            result = result == 0 ? o1.getAuthor().compareTo(o2.getAuthor()) : result;
            result = result == 0 ? o1.getTitle().compareTo(o2.getTitle()) : result;
            return result;
        });
        t.add(new Book("玫瑰的名字","hhh",35));
        t.add(new Book("玫瑰的名字","hhh",35));
        t.add(new Book("梦的解析","yyy",35));
        t.add(new Book("时间简史","yyy",33));
        t.add(new Book("百年孤独","hhh",35));
        for (Book book : t) {
            System.out.println(book);
        }
    }
}
class Book {
    private String title;
    private String author;
    private int price;

    @Override
    public String toString() {
        return "Book{" +
                "title='" + title + '\'' +
                ", author='" + author + '\'' +
                ", price=" + price +
                '}';
    }

    public Book() {
    }

    public Book(String title, String author, int price) {
        this.title = title;
        this.author = author;
        this.price = price;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }
}